using System;
using System.Data;
using System.Collections.Generic;
using ADOBase;
namespace eTMS.DAO{
	/********************************BEGIN TonGiaoDAO****************************************/
	///<summary>
	/// <para>Author: Auto generated class by CSharp Code Generator v2.0</para>
	/// <para>Date:26/10/2011 34:05:09</para>
	/// <para>Class Name: TonGiaoDAO</para>
	/// <para>Description: Class access to table TonGiao in database. Coder should'nt code here.</para>
	///</summary>

	
	public partial class TonGiaoDAO : DAOBase<TonGiaoEntity>{


		#region Select functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateSelectOneCommand</para>
		/// <para>Input: TonGiao_ID</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectOneCommand(int TonGiao_ID){
			string strSQL="SELECT  [TonGiao_ID],[MaTonGiao],[TenTonGiao],[MoTaTonGiao] FROM [TonGiao]  WHERE [TonGiao].[TonGiao_ID]=@TonGiao_ID";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@TonGiao_ID",TonGiao_ID);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SelectOne</para>
		/// <para>Input: TonGiao_ID</para>
		/// <para>Output: TonGiaoEntity</para>
		///</summary>
		public TonGiaoEntity SelectOne(int TonGiao_ID){
			IDbCommand cmd=this.CreateSelectOneCommand(TonGiao_ID);
			return this.Select(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SelectOneByMaTonGiao</para>
		/// <para>Input: MaTonGiao</para>
		/// <para>Output: TonGiaoEntity</para>
		///</summary>
		public TonGiaoEntity SelectOneByMaTonGiao(string MaTonGiao){
			IDbCommand cmd=this.CreateSelectAllByKeyCommand("MaTonGiao",MaTonGiao);
			return this.Select(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateSelectAllCommand</para>
		/// <para>Input: </para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllCommand(){
			string strSQL="SELECT  [TonGiao_ID],[MaTonGiao],[TenTonGiao],[MoTaTonGiao] FROM [TonGiao] ";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateSelectAllByKeyCommand</para>
		/// <para>Input: ColumnName,ColumnValue</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllByKeyCommand(string ColumnName,object Value){
			string strSQL="SELECT  [TonGiao_ID],[MaTonGiao],[TenTonGiao],[MoTaTonGiao] FROM [TonGiao]  WHERE [TonGiao].["+ColumnName+"]=@ColumnName";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@ColumnName",Value);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SelectAll</para>
		/// <para>Input: </para>
		/// <para>Output: List of TonGiaoEntity</para>
		///</summary>
		public List<TonGiaoEntity> SelectAll(){
			IDbCommand cmd=this.CreateSelectAllCommand();
			return this.SelectList(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SelectAllDS</para>
		/// <para>Input: </para>
		/// <para>Output: DataSet</para>
		///</summary>
		public DataSet SelectAllDS(){
			IDbCommand cmd=this.CreateSelectAllCommand();
			return this.SelectDS(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateSelectAllFilterCommand</para>
		/// <para>Input: </para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllFilterCommand(string strFilter){
			string strSQL="SELECT  [TonGiao_ID],[MaTonGiao],[TenTonGiao],[MoTaTonGiao] FROM [TonGiao]  WHERE "+RemoveInjection(strFilter);
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateSelectAllByKeyFilterCommand</para>
		/// <para>Input: ColumnName,ColumnValue</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllByKeyFilterCommand(string strFilter,string ColumnName,object Value){
			string strSQL="SELECT  [TonGiao_ID],[MaTonGiao],[TenTonGiao],[MoTaTonGiao] FROM [TonGiao]  WHERE [TonGiao].["+ColumnName+"]=@ColumnName AND "+RemoveInjection(strFilter);
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@ColumnName",Value);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SelectAll</para>
		/// <para>Input: </para>
		/// <para>Output: List of TonGiaoEntity</para>
		///</summary>
		public List<TonGiaoEntity> SelectAllFilter(string strFilter){
			IDbCommand cmd=this.CreateSelectAllFilterCommand(strFilter);
			return this.SelectList(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SelectAllDSFilter</para>
		/// <para>Input: </para>
		/// <para>Output: DataSet</para>
		///</summary>
		public DataSet SelectAllDSFilter(string strFilter){
			IDbCommand cmd=this.CreateSelectAllFilterCommand(strFilter);
			return this.SelectDS(cmd);
		}
		#endregion

		#region Insert functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateInsertCommand</para>
		/// <para>Input: TonGiaoEntity</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateInsertCommand(TonGiaoEntity o){
			string strSQL="INSERT INTO [TonGiao]([MaTonGiao],[TenTonGiao],[MoTaTonGiao]) VALUES  (@MaTonGiao,@TenTonGiao,@MoTaTonGiao);SELECT  @@IDENTITY";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			if(o.IsNullMaTonGiao)
				this.CreateCommandParameter(cmd,"@MaTonGiao",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@MaTonGiao",o.MaTonGiao);

			if(o.IsNullTenTonGiao)
				this.CreateCommandParameter(cmd,"@TenTonGiao",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@TenTonGiao",o.TenTonGiao);

			if(o.IsNullMoTaTonGiao)
				this.CreateCommandParameter(cmd,"@MoTaTonGiao",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@MoTaTonGiao",o.MoTaTonGiao);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: Save</para>
		/// <para>Input: TonGiaoEntity</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool Save(TonGiaoEntity o){
			bool result=false;
			IDbCommand cmd=this.CreateInsertCommand(o);
			object id=this.ExecuteScalar(cmd,ref result);
			cmd.Dispose();
			try{
				o.TonGiao_ID=int.Parse(Convert.ToString(id));
			}
			catch{}
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SaveList</para>
		/// <para>Input: List of TonGiaoEntity</para>
		/// <para>Output: </para>
		///</summary>
		public void SaveList(List<TonGiaoEntity>list){
			foreach(TonGiaoEntity o in list){
				try{
					this.Save(o);
				}
				catch{
				}
			}
		}
		#endregion

		#region Update functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateUpdateCommand</para>
		/// <para>Input: TonGiaoEntity</para>
		/// <para>Output: </para>
		///</summary>
		protected IDbCommand CreateUpdateCommand(TonGiaoEntity o){
			string strSQL="UPDATE  [TonGiao] SET [TonGiao].[MaTonGiao]=@MaTonGiao,[TonGiao].[TenTonGiao]=@TenTonGiao,[TonGiao].[MoTaTonGiao]=@MoTaTonGiao WHERE [TonGiao].[TonGiao_ID]=@TonGiao_ID";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			if(o.IsNullTonGiao_ID)
				this.CreateCommandParameter(cmd,"@TonGiao_ID",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@TonGiao_ID",o.TonGiao_ID);

			if(o.IsNullMaTonGiao)
				this.CreateCommandParameter(cmd,"@MaTonGiao",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@MaTonGiao",o.MaTonGiao);

			if(o.IsNullTenTonGiao)
				this.CreateCommandParameter(cmd,"@TenTonGiao",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@TenTonGiao",o.TenTonGiao);

			if(o.IsNullMoTaTonGiao)
				this.CreateCommandParameter(cmd,"@MoTaTonGiao",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@MoTaTonGiao",o.MoTaTonGiao);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateUpdateFieldCommand</para>
		/// <para>Input: ColumnName,ColumnValue,TonGiao_ID</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateUpdateFieldCommand(string ColumnName,object Value,int TonGiao_ID){
			string strSQL="UPDATE  [TonGiao] SET [TonGiao].["+ColumnName+"]=@ColumnName WHERE [TonGiao].[TonGiao_ID]=@TonGiao_ID";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@TonGiao_ID",TonGiao_ID);



			this.CreateCommandParameter(cmd,"@ColumnName",Value);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: Update</para>
		/// <para>Input: TonGiaoEntity</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool Update(TonGiaoEntity o){
			IDbCommand cmd=this.CreateUpdateCommand(o);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: UpdateList</para>
		/// <para>Input: List of TonGiaoEntity</para>
		/// <para>Output: </para>
		///</summary>
		public void UpdateList(List<TonGiaoEntity>list){
			foreach(TonGiaoEntity o in list){
				try{
					this.Update(o);
				}
				catch{
				}
			}
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: UpdateMaTonGiao</para>
		/// <para>Input: NewMaTonGiao,TonGiao_ID</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateMaTonGiao(string NewMaTonGiao,int TonGiao_ID){
			IDbCommand cmd=this.CreateUpdateFieldCommand("MaTonGiao",NewMaTonGiao,TonGiao_ID);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: UpdateTenTonGiao</para>
		/// <para>Input: NewTenTonGiao,TonGiao_ID</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateTenTonGiao(string NewTenTonGiao,int TonGiao_ID){
			IDbCommand cmd=this.CreateUpdateFieldCommand("TenTonGiao",NewTenTonGiao,TonGiao_ID);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: UpdateMoTaTonGiao</para>
		/// <para>Input: NewMoTaTonGiao,TonGiao_ID</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateMoTaTonGiao(string NewMoTaTonGiao,int TonGiao_ID){
			IDbCommand cmd=this.CreateUpdateFieldCommand("MoTaTonGiao",NewMoTaTonGiao,TonGiao_ID);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		#endregion

		#region Delete functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: DeleteAllCommand</para>
		/// <para>Input: </para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteAllCommand(){
			string strSQL="DELETE   FROM [TonGiao]  ";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: DeleteCommand</para>
		/// <para>Input: TonGiaoEntity</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteCommand(TonGiaoEntity o){
			string strSQL="DELETE   FROM [TonGiao]   WHERE [TonGiao].[TonGiao_ID]=@TonGiao_ID";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			if(o.IsNullTonGiao_ID)
				this.CreateCommandParameter(cmd,"@TonGiao_ID",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@TonGiao_ID",o.TonGiao_ID);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: DeleteAll</para>
		/// <para>Input: </para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool DeleteAll(){
			IDbCommand cmd=this.CreateDeleteAllCommand();
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateDeleteByPrimaryKeyCommand</para>
		/// <para>Input: TonGiao_ID</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteByPrimaryKeyCommand(int TonGiao_ID){
			string strSQL="DELETE   FROM [TonGiao]   WHERE [TonGiao].[TonGiao_ID]=@TonGiao_ID";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@TonGiao_ID",TonGiao_ID);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateDeleteByKeyCommand</para>
		/// <para>Input: ColumnName , ColumnValue</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteByKeyCommand(string ColumnName,object Value){
			string strSQL="DELETE   FROM [TonGiao]   WHERE [TonGiao].["+ColumnName+"]=@ColumnName";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@ColumnName",Value);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: Delete</para>
		/// <para>Input: TonGiaoEntity</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool Delete(TonGiaoEntity o){
			IDbCommand cmd=this.CreateDeleteCommand(o);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: DeleteByID</para>
		/// <para>Input: TonGiao_ID</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool DeleteByID(int TonGiao_ID){
			IDbCommand cmd=this.CreateDeleteByPrimaryKeyCommand(TonGiao_ID);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		#endregion

		#region Select,delete by TonGiao_ID functions
		#endregion

		#region MapObject functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: MapObject</para>
		/// <para>Input: IDataReader</para>
		/// <para>Output: TonGiaoEntity</para>
		///</summary>
		protected override TonGiaoEntity MapObject(IDataReader r){
			TonGiaoEntity entity = new TonGiaoEntity();
			try{
				if(r.FieldCount>0){
					try
					{
						int ordinal = r.GetOrdinal("TonGiao_ID");
						if (!r.IsDBNull(ordinal)) entity.TonGiao_ID = ((int)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("MaTonGiao");
						if (!r.IsDBNull(ordinal)) entity.MaTonGiao = ((string)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("TenTonGiao");
						if (!r.IsDBNull(ordinal)) entity.TenTonGiao = ((string)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("MoTaTonGiao");
						if (!r.IsDBNull(ordinal)) entity.MoTaTonGiao = ((string)(r.GetValue(ordinal)));
					}
					catch{}
					return entity;
				}
			}catch{}
			return null;
		}
		#endregion
	}
	/*****************************************************************************************************/
	/**********************************END TonGiaoDAOBase*****************************************/
	/*****************************************************************************************************/
}

